<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>nrf51/Include/nrf_gpiote.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51 General Code Examples
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('nrf__gpiote_8h.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">nrf51/Include/nrf_gpiote.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef NRF_GPIOTE_H__</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define NRF_GPIOTE_H__</span>
<a name="l00003"></a>00003 <span class="preprocessor"></span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &quot;nrf51.h&quot;</span>
<a name="l00005"></a>00005 
<a name="l00018"></a><a class="code" href="group__nrf__gpiote.html#ga9a424db0997c11092f8f69d52155dd9d">00018</a> <span class="keyword">typedef</span> <span class="keyword">enum</span>
<a name="l00019"></a>00019 {
<a name="l00020"></a><a class="code" href="group__nrf__gpiote.html#gga9a424db0997c11092f8f69d52155dd9da59dda358a841a81671bd372058b46498">00020</a>   <a class="code" href="group__nrf__gpiote.html#gga9a424db0997c11092f8f69d52155dd9da59dda358a841a81671bd372058b46498" title="Low to high.">NRF_GPIOTE_POLARITY_LOTOHI</a> = GPIOTE_CONFIG_POLARITY_LoToHi,       
<a name="l00021"></a><a class="code" href="group__nrf__gpiote.html#gga9a424db0997c11092f8f69d52155dd9da97c193ac03f0691bea38c2283b55fa8a">00021</a>   <a class="code" href="group__nrf__gpiote.html#gga9a424db0997c11092f8f69d52155dd9da97c193ac03f0691bea38c2283b55fa8a" title="High to low.">NRF_GPIOTE_POLARITY_HITOLO</a> = GPIOTE_CONFIG_POLARITY_HiToLo,       
<a name="l00022"></a><a class="code" href="group__nrf__gpiote.html#gga9a424db0997c11092f8f69d52155dd9da00487cd8286ff071ca751cd4a00295d5">00022</a>   <a class="code" href="group__nrf__gpiote.html#gga9a424db0997c11092f8f69d52155dd9da00487cd8286ff071ca751cd4a00295d5" title="Toggle.">NRF_GPIOTE_POLARITY_TOGGLE</a> = GPIOTE_CONFIG_POLARITY_Toggle        
<a name="l00023"></a>00023 } <a class="code" href="group__nrf__gpiote.html#ga9a424db0997c11092f8f69d52155dd9d" title="Polarity for GPIOTE channel enumerator.">nrf_gpiote_polarity_t</a>;
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 
<a name="l00030"></a><a class="code" href="group__nrf__gpiote.html#gab280bbb7269ab98a97e7b47d906ef9aa">00030</a> <span class="keyword">typedef</span> <span class="keyword">enum</span>
<a name="l00031"></a>00031 {
<a name="l00032"></a><a class="code" href="group__nrf__gpiote.html#ggab280bbb7269ab98a97e7b47d906ef9aaae0df1a0e930bfe3b198a9692d9916667">00032</a>   <a class="code" href="group__nrf__gpiote.html#ggab280bbb7269ab98a97e7b47d906ef9aaae0df1a0e930bfe3b198a9692d9916667" title="Low to high.">NRF_GPIOTE_INITIAL_VALUE_LOW</a>  = GPIOTE_CONFIG_OUTINIT_Low,       
<a name="l00033"></a><a class="code" href="group__nrf__gpiote.html#ggab280bbb7269ab98a97e7b47d906ef9aaa1fc9af8ce3fcd7165b3c090b564e9aa4">00033</a>   <a class="code" href="group__nrf__gpiote.html#ggab280bbb7269ab98a97e7b47d906ef9aaa1fc9af8ce3fcd7165b3c090b564e9aa4" title="High to low.">NRF_GPIOTE_INITIAL_VALUE_HIGH</a> = GPIOTE_CONFIG_OUTINIT_High       
<a name="l00034"></a>00034 } <a class="code" href="group__nrf__gpiote.html#gab280bbb7269ab98a97e7b47d906ef9aa" title="Initial output value for GPIOTE channel enumerator.">nrf_gpiote_outinit_t</a>;
<a name="l00035"></a>00035 
<a name="l00036"></a>00036 
<a name="l00046"></a><a class="code" href="group__nrf__gpiote.html#gab8667667ddf3bdca874df3add96fb622">00046</a> <span class="keyword">static</span> __INLINE <span class="keywordtype">void</span> <a class="code" href="group__nrf__gpiote.html#gab8667667ddf3bdca874df3add96fb622" title="Config GPIOTE channel as output, setting the properly desired output level.">nrf_gpiote_task_config</a>(uint32_t channel_number, uint32_t pin_number, <a class="code" href="group__nrf__gpiote.html#ga9a424db0997c11092f8f69d52155dd9d" title="Polarity for GPIOTE channel enumerator.">nrf_gpiote_polarity_t</a> polarity, <a class="code" href="group__nrf__gpiote.html#gab280bbb7269ab98a97e7b47d906ef9aa" title="Initial output value for GPIOTE channel enumerator.">nrf_gpiote_outinit_t</a> initial_value)
<a name="l00047"></a>00047 {
<a name="l00048"></a>00048     <span class="comment">/* Check if the output desired is high or low */</span>
<a name="l00049"></a>00049     <span class="keywordflow">if</span> (initial_value == <a class="code" href="group__nrf__gpiote.html#ggab280bbb7269ab98a97e7b47d906ef9aaae0df1a0e930bfe3b198a9692d9916667" title="Low to high.">NRF_GPIOTE_INITIAL_VALUE_LOW</a>)
<a name="l00050"></a>00050     {
<a name="l00051"></a>00051         <span class="comment">/* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */</span>
<a name="l00052"></a>00052         NRF_GPIOTE-&gt;CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task       &lt;&lt; GPIOTE_CONFIG_MODE_Pos)     |
<a name="l00053"></a>00053                                              (31UL                          &lt;&lt; GPIOTE_CONFIG_PSEL_Pos)     |
<a name="l00054"></a>00054                                              (GPIOTE_CONFIG_POLARITY_HiToLo &lt;&lt; GPIOTE_CONFIG_POLARITY_Pos);                                    
<a name="l00055"></a>00055     } 
<a name="l00056"></a>00056     <span class="keywordflow">else</span> 
<a name="l00057"></a>00057     {
<a name="l00058"></a>00058         <span class="comment">/* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */</span>
<a name="l00059"></a>00059         NRF_GPIOTE-&gt;CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task       &lt;&lt; GPIOTE_CONFIG_MODE_Pos)     |
<a name="l00060"></a>00060                                              (31UL                          &lt;&lt; GPIOTE_CONFIG_PSEL_Pos)     |
<a name="l00061"></a>00061                                              (GPIOTE_CONFIG_POLARITY_LoToHi &lt;&lt; GPIOTE_CONFIG_POLARITY_Pos);
<a name="l00062"></a>00062     }
<a name="l00063"></a>00063 
<a name="l00064"></a>00064     <span class="comment">/* Three NOPs are required to make sure configuration is written before setting tasks or getting events */</span>
<a name="l00065"></a>00065     __NOP();
<a name="l00066"></a>00066     __NOP();
<a name="l00067"></a>00067     __NOP(); 
<a name="l00068"></a>00068 
<a name="l00069"></a>00069     <span class="comment">/* Launch the task to take the GPIOTE channel output to the desired level */</span>
<a name="l00070"></a>00070     NRF_GPIOTE-&gt;TASKS_OUT[channel_number] = 1;
<a name="l00071"></a>00071 
<a name="l00072"></a>00072     <span class="comment">/* Finally configure the channel as the caller expects. If OUTINIT works, the channel is configured properly. </span>
<a name="l00073"></a>00073 <span class="comment">       If it does not, the channel output inheritance sets the proper level. */</span>
<a name="l00074"></a>00074     NRF_GPIOTE-&gt;CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task &lt;&lt; GPIOTE_CONFIG_MODE_Pos)     |
<a name="l00075"></a>00075                                          ((uint32_t)pin_number    &lt;&lt; GPIOTE_CONFIG_PSEL_Pos)     |
<a name="l00076"></a>00076                                          ((uint32_t)polarity      &lt;&lt; GPIOTE_CONFIG_POLARITY_Pos) |
<a name="l00077"></a>00077                                          ((uint32_t)initial_value &lt;&lt; GPIOTE_CONFIG_OUTINIT_Pos);
<a name="l00078"></a>00078 
<a name="l00079"></a>00079     <span class="comment">/* Three NOPs are required to make sure configuration is written before setting tasks or getting events */</span>
<a name="l00080"></a>00080     __NOP();
<a name="l00081"></a>00081     __NOP();
<a name="l00082"></a>00082     __NOP(); 
<a name="l00083"></a>00083 }
<a name="l00084"></a>00084 
<a name="l00098"></a><a class="code" href="group__nrf__gpiote.html#gac04dde3ea740f163fa2ac032bf56152d">00098</a> <span class="keyword">static</span> __INLINE <span class="keywordtype">void</span> <a class="code" href="group__nrf__gpiote.html#gac04dde3ea740f163fa2ac032bf56152d" title="Config GPIOTE channel as input, automatically clearing an event that appears in some cases nder confi...">nrf_gpiote_event_config</a>(uint32_t channel_number, uint32_t pin_number, <a class="code" href="group__nrf__gpiote.html#ga9a424db0997c11092f8f69d52155dd9d" title="Polarity for GPIOTE channel enumerator.">nrf_gpiote_polarity_t</a> polarity)
<a name="l00099"></a>00099 {   
<a name="l00100"></a>00100     <span class="comment">/* Configure the channel as the caller expects */</span>
<a name="l00101"></a>00101     NRF_GPIOTE-&gt;CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Event &lt;&lt; GPIOTE_CONFIG_MODE_Pos)     |
<a name="l00102"></a>00102                                          ((uint32_t)pin_number     &lt;&lt; GPIOTE_CONFIG_PSEL_Pos)     |
<a name="l00103"></a>00103                                          ((uint32_t)polarity       &lt;&lt; GPIOTE_CONFIG_POLARITY_Pos);
<a name="l00104"></a>00104 
<a name="l00105"></a>00105     <span class="comment">/* Three NOPs are required to make sure configuration is written before setting tasks or getting events */</span>
<a name="l00106"></a>00106     __NOP();
<a name="l00107"></a>00107     __NOP();
<a name="l00108"></a>00108     __NOP();
<a name="l00109"></a>00109     
<a name="l00110"></a>00110     <span class="comment">/* Clear the event that appears in some cases */</span>
<a name="l00111"></a>00111     NRF_GPIOTE-&gt;EVENTS_IN[channel_number] = 0; 
<a name="l00112"></a>00112 }
<a name="l00113"></a>00113 
<a name="l00114"></a>00114 
<a name="l00123"></a><a class="code" href="group__nrf__gpiote.html#gae721c9782910048854960a6db18ab2ef">00123</a> <span class="keyword">static</span> __INLINE <span class="keywordtype">void</span> <a class="code" href="group__nrf__gpiote.html#gae721c9782910048854960a6db18ab2ef" title="Unconfig GPIOTE channel.">nrf_gpiote_unconfig</a>(uint32_t channel_number)
<a name="l00124"></a>00124 {   
<a name="l00125"></a>00125     <span class="comment">/* Unonfigure the channel as the caller expects */</span>
<a name="l00126"></a>00126     NRF_GPIOTE-&gt;CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Disabled   &lt;&lt; GPIOTE_CONFIG_MODE_Pos) |
<a name="l00127"></a>00127                                          (31UL                          &lt;&lt; GPIOTE_CONFIG_PSEL_Pos) |
<a name="l00128"></a>00128                                          (GPIOTE_CONFIG_POLARITY_Toggle &lt;&lt; GPIOTE_CONFIG_POLARITY_Pos);
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 
<a name="l00134"></a>00134 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>nrf_gpiote.h</b>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
